﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Net_SCADA
{
    public class Alarm
    {
        private bool _isChanged = false;
        private bool _alValue=false;
        public int AlarmID { get; set; }
        public string[] AlarmName { get; set; }
        public int AlarmTypeID { get; set; }
        public int AlarmLevel { get; set; }
        public string AlarmAdd { get; set; }
        public int AlarmWordIndex { get; set; }
        public int AlarmBitIndex { get; set; }
        public string AlarmEquipID { get; set; }
        public List<int> AlarmPostion { get; private set; } = new List<int>();
        public int AlarmAction { get; set; } = 0;
        public bool AlarmValue
        {
            get => _alValue;
            set
            {
                if (_alValue != value)
                {
                    _isChanged = true;
                    _alValue = value;
                }
            }
        }

        public void SetAlarmPostion(string alpostion)
        {
            if (alpostion == "") return;
            string[] pos=alpostion.Split(new char[]{ ','},StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0 ; i < pos.Length ; i++)
            {
                if(int.TryParse(pos[i],out int v))
                {
                    AlarmPostion.Add(v);
                }
            }
        }
        public bool IsChanged
        {
            get
            {
                bool v=_isChanged;
                _isChanged = false;
                return v;
            }
        }
    }
}
